package com.ruoyi.business.controller;

import com.ruoyi.business.domain.MobileUserCoupon;
import com.ruoyi.business.service.IMobileUserCouponService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author liumaotong
 * @Description 我的优惠券
 * @Date 2024/6/14
 */
@RestController
@RequestMapping("/mobile/coupon")
public class MobileUserCouponController extends BaseController {

    @Autowired
    private IMobileUserCouponService couponService;

    /**
     * @Author liumaotong
     * @Description 领取优惠券
     * @Date 2024/6/14
     * @Param [openId]
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @RequestMapping(value = "/getCoupon",method = RequestMethod.GET)
    public AjaxResult getCoupon(@RequestParam("openId") String openId){
        couponService.getCoupon(openId);
        return AjaxResult.success("领取成功");
    }

    /**
     * @Author liumaotong
     * @Description 查看我的优惠券（展示二维码）
     * @Date 2024/6/14
     * @Param [openId]
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @RequestMapping(value = "/selectMyQrCode",method = RequestMethod.GET)
    public AjaxResult selectMyQrCode(@RequestParam("openId") String openId) throws Exception {
        return AjaxResult.success(couponService.selectMyQrCode(openId));
    }

    /**
     * @Author liumaotong
     * @Description 核销优惠券
     * @Date 2024/6/14
     * @Param [qrcode]
     * @return com.ruoyi.common.core.domain.AjaxResult
     */
    @RequestMapping(value = "/costCoupon",method = RequestMethod.POST)
    public AjaxResult costCoupon(@RequestBody MobileUserCoupon coupon){
        couponService.costCoupon(coupon);
        return AjaxResult.success("核销成功");
    }

    /**
     * 查询我的优惠券列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MobileUserCoupon mobileUserCoupon) {
        startPage();
        List<MobileUserCoupon> list = couponService.selectMobileUserCouponList(mobileUserCoupon);
        return getDataTable(list);
    }

    /**
     * 导出我的优惠券列表
     */
    @Log(title = "我的优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MobileUserCoupon mobileUserCoupon) {
        List<MobileUserCoupon> list = couponService.selectMobileUserCouponList(mobileUserCoupon);
        ExcelUtil<MobileUserCoupon> util = new ExcelUtil<MobileUserCoupon>(MobileUserCoupon.class);
        util.exportExcel(response, list, "我的优惠券数据");
    }
}
